package cn.hchaojie.daily.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hchaojie.daily.dao.DailyDao;
import cn.hchaojie.daily.dao.impl.DailyDaoImpl;
import cn.hchaojie.daily.entity.Daily;

@WebServlet("/dailies/add")
public class DailyAddServlet extends HttpServlet {
	private DailyDao dao = new DailyDaoImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String digest = req.getParameter("digest");
		String content = req.getParameter("content");
		
		// 当前日报关联的关键字（注意关键字如果在系统里面已经有了，需要重用系统的关键字）
		String[] keywords = req.getParameterMap().get("keywords");
		
		Daily daily = new Daily();
		daily.setContent(content);
		daily.setDigest(digest);
		daily.setCreated(new Date());
		daily.setUid(1L);
		
		dao.insert(daily, keywords);
	}
}
